public class BinaryTree {
    static class Tree{
        public char val;
        public Tree left;
        public Tree right;
        public Tree(char val){
            this.val = val;
        }
    }
    public Tree GreatTree(){
        Tree A = new Tree('A');
        Tree B = new Tree('B');
        Tree C = new Tree('C');
        Tree D = new Tree('D');
        Tree E = new Tree('E');
        Tree F = new Tree('F');
        Tree G = new Tree('G');
        Tree H = new Tree('H');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        E.right = H;
        return A;
    }
    //前序遍历
    public void TreeNode(Tree root){
        if (root == null){
            return;
        }
        System.out.print(" " + root.val);
        TreeNode(root.left);
        TreeNode(root.right);
    }
    //后序遍历
    public void TreeNode2(Tree root){
        if (root == null){
            return;
        }
        TreeNode2(root.left);
        TreeNode2(root.right);
        System.out.print(" " + root.val);
    }
    //中序遍历
    public void TreeNode3(Tree root){
        if (root == null){
            return;
        }
        TreeNode3(root.left);
        System.out.print(" " + root.val);
        TreeNode3(root.right);
    }
    //求二叉树节点的个数
    int size(Tree root){
        if (root == null){
            return 0;
        }
        return size(root.right) + size(root.left) + 1;
    }
    //求二叉树叶子节点的个数
    int getleafcount(Tree root){
        if (root == null){
            return 0;
        }
        if (root.left == null && root.right == null){
            return 1;
        }
        return getleafcount(root.left) + getleafcount(root.right);
    }
    //获取第K层节点的个数
    int geileafcount(Tree root,int k){
        if (root  == null){
            return 1;
        }
        if (k == 1){
            return 1;
        }
        return geileafcount(root,k - 1) + geileafcount(root, k - 1);
    }
    //获取二叉树的高度
    int gethight(Tree root){
        if(root == null){
            return 0;
        }
        int lefthight = gethight(root.left);
        int righthight = gethight(root.right);
        if (lefthight > righthight){
            return lefthight + 1;
        }else {
            return righthight + 1;
        }
    }
    //检测值为value的元素是否存在
    Boolean find(Tree root,char value){
        if (root == null){
            return false;
        }
        if (root.val == value){
            return true;
        }

        return find(root.left,value ) || find(root.right,value);
    }
    //层序遍历
    void levelOrder(Tree root){
        System.out.println(root.val);
        levelOrder(root.left);
    }
    //判断一棵树是不是完全二叉树
    Boolean isCompleteTree(Tree root){
        return true;
    }
}
